<template>
  <div class="saearch-block-container">
    <el-row>
      <el-col :span="5">
        <el-input
          @keyup.enter.native="handleSearch"
          clearable
          placeholder="请输入昵称"
          size="small"
          v-model="searchParams.nickname"
        ></el-input>
      </el-col>
      <el-col :span="5" :offset="1">
        <el-input
          @keyup.enter.native="handleSearch"
          clearable
          placeholder="请输入微信号"
          size="small"
          v-model="searchParams.wechatNumber"
        ></el-input>
      </el-col>
      <el-col :span="5" :offset="1">
        <el-select clearable placeholder="请选择分组" size="small" v-model="searchParams.groupId">
          <el-option
            :key="item.id"
            :label="item.title"
            :value="item.id"
            v-for="item in userGroupList"
          ></el-option>
        </el-select>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'SearchBlock',
  props: {
    userGroupList: Array
  },
  computed: {
    groupId() {
      return this.searchParams.groupId
    }
  },
  watch: {
    groupId(newVal, oldVal) {
      if (newVal === '') {
        this.searchParams.groupId = null
      }
      this.handleSearch()
    }
  },
  methods: {
    handleSearch() {
      this.$emit('handleSearch', this.searchParams)
    }
  },
  data() {
    return {
      searchParams: {
        nickname: null,
        wechatNumber: null,
        groupId: null
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>

